import axios from 'axios'
import { Toast} from "antd-mobile";
axios.defaults.timeout = 5000
axios.defaults.baseURL = '/v9'
axios.interceptors.request.use(configs=>{
    Toast.loading('正在加载...',10)
    return configs
},err=>{
    Toast.hide()
    return err
})
axios.interceptors.response.use(response=>{
    Toast.hide()
    return response.data;
},err=>{
    Toast.hide()
    return err
})
export default {
    get: function (path = '', data = {}) {
        return new Promise(function (resolve, reject) {
            axios.get(path, {
                params: data
            })
                .then(function (response) {
                    resolve(response.data)
                })
                .catch(function (error) {
                    reject(error)
                })
        })
    },
    post: function (path = '', data = {}) {
        return new Promise(function (resolve, reject) {
            axios.post(path, data)
                .then(function (response) {
                    resolve(response.data)
                })
                .catch(function (error) {
                    reject(error)
                })
        })
    },
    all: function (list) {
        return new Promise(function (resolve, reject) {
            axios.all(list)
                .then(axios.spread(function (...result) {
                    // 两个请求现在都执行完成
                    resolve(result)
                }))
                .catch(function (err) {
                    reject(err)
                })
        })
    }
}
